#include <iostream>
#include <string>
#include <unordered_map>

bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= int(sqrt(n)); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

void closest_prime_number(std::string s) {
    std::unordered_map<std::string, int> num_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3},
        {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7},
        {"eight", 8}, {"nine", 9}
    };

    std::vector<std::string> words;
    std::string word = "";
    for (char c : s) {
        if (c == ' ') {
            words.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    words.push_back(word);

    if (words.size() != 3) {
        std::cout << "wrong input" << std::endl;
        return;
    }

    int num = 0;
    for (std::string word : words) {
        num = num * 10 + num_dict[word];
    }

    if (num < 100 || num > 999) {
        std::cout << "wrong input" << std::endl;
        return;
    }

    int lower_prime = num;
    int upper_prime = num;
    while (true) {
        if (is_prime(lower_prime)) {
            std::cout << lower_prime << std::endl;
            return;
        }
        if (is_prime(upper_prime)) {
            std::cout << upper_prime << std::endl;
            return;
        }
        lower_prime--;
        upper_prime++;
    }
}

int main() {
    std::string input_text;
    std::cout << "Enter numbers: ";
    std::getline(std::cin, input_text);
    closest_prime_number(input_text);

    return 0;
}